//import java.util.*;
//
//public class Leet1765_2 {
//    public static void main(String[] args) {
////        int[][] is = {{0,0},{1,1},{1,0}};
//        int[][] is = {{0,0,1,0,0,0,1,0,0,1},{0,0,0,0,1,0,0,0,0,0},{0,0,1,0,0,0,0,1,0,0},{0,0,0,1,0,0,0,1,0,0},{1,0,0,1,0,0,0,0,0,0},{0,0,0,1,1,0,1,0,0,0},{0,0,0,0,0,1,0,0,1,0},{0,0,0,0,0,0,0,0,1,0},{1,1,1,0,0,0,0,0,1,1},{0,0,0,1,0,1,1,0,0,0},{0,1,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,0},{1,0,0,1,0,0,0,0,0,0},{0,0,0,0,0,1,0,0,0,0},{0,0,1,1,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,1,1,0,0,1,0},{0,0,0,0,0,0,1,0,1,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,1,1,0,0,0},{0,1,1,0,0,1,1,0,0,0},{0,0,0,1,1,1,0,0,0,0},{0,0,1,0,0,0,0,1,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,1,0,0,1,1,0,0,0},{0,0,0,0,0,1,0,0,0,0}};
//        Leet1765_2 l = new Leet1765_2();
//        System.out.println(Arrays.deepToString(l.highestPeak(is)));
//    }
//    public int[][] highestPeak(int[][] isWater) {
//        List<Queue<Module12>> queues = new ArrayList<>();
//        for (int i = 0; i <isWater.length; i++) {
//            for (int j = 0; j < isWater[0].length; j++) {
//                if (isWater[i][j] == 1) {
//                    Queue<Module12> queue = new LinkedList<>();
//                    queue.add(new Module12(j, i, 0));
//                    queues.add(queue);
//                }
//            }
//        }
//        int[][] re = new int[isWater.length][isWater[0].length];
//        while (!queues.isEmpty())
//        for (Queue<Module12> queue : queues) {
//            if (queue.isEmpty()){
//                queues.remove(queue);
//                break;
//            }
//            int x = queue.peek().x;
//            int y = queue.peek().y;
//            int num = queue.peek().num;
//            re[y][x] = num;
//            isWater[y][x] = -1;
//            if (x>0&&isWater[y][x-1]==0&&re[y][x-1]==0){
//                queue.add(new Module12(x-1,y,num+1));
//                isWater[y][x-1] = -1;
//            }
//            if (y>0&&isWater[y-1][x]==0&&re[y-1][x]==0){
//                queue.add(new Module12(x,y-1,num+1));
//                isWater[y-1][x] = -1;
//            }
//            if (x<re[0].length-1&&isWater[y][x+1]==0&&re[y][x+1]==0){
//                queue.add(new Module12(x+1,y,num+1));
//                isWater[y][x+1] = -1;
//            }
//            if (y<re.length-1&&isWater[y+1][x]==0&&re[y+1][x]==0){
//                queue.add(new Module12(x,y+1,num+1));
//                isWater[y+1][x] = -1;
//            }
//            queue.poll();
//        }
//        for (int t = 0; t < 10; t++) {
//            for (int i = 0; i < re.length; i++) {
//                for (int j = 0; j < re[0].length; j++) {
//                    if (i>0)
//                        re[i][j] = Math.min(re[i][j],re[i-1][j]+1);
//                    if (i<re.length-1)
//                        re[i][j] = Math.min(re[i][j],re[i+1][j]+1);
//                    if (j>0)
//                        re[i][j] = Math.min(re[i][j],re[i][j-1]+1);
//                    if (j<re[0].length-1)
//                        re[i][j] = Math.min(re[i][j],re[i][j+1]+1);
//
//                }
//            }
//        }
//
//        return re;
//    }
//}
//class Module123{
//    int x,y,num;
//
//    public Module123(int x, int y, int num) {
//        this.x = x;
//        this.y = y;
//        this.num = num;
//    }
//}